﻿<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>智慧工地管理平台</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script src="<%=path%>/resources/jquery/jquery-3.2.1.min.js"></script>
    <link href="<%=path%>/resources/css/login.css" rel="stylesheet" type="text/css"/>
    </meta>
</head>
<body>
<h1>智慧工地管理平台<sup>V2017</sup></h1>

<div class="login" style="margin-top:50px;">

    <div class="header" style='font-size:18px;text-align:center;'>
        <p>快速登录</p>
    </div>


    <div class="web_qr_login" id="web_qr_login" style="display: block; height: 235px;">

        <!--登录-->
        <div class="web_login" id="web_login">


            <div class="login-box">


                <div class="login_form">
                    <!-- <form action="../../user!toLogin" name="loginform" accept-charset="utf-8" id="login_form" class="loginForm" method="post"> -->
                    <div name="loginform" id="login_form" class="loginForm">
                        <input type="hidden" name="did" value="0"/>
                        <input type="hidden" name="to" value="log"/>
                        <div class="uinArea" id="uinArea">
                            <label class="input-tips" for="u">帐号：</label>
                            <div class="inputOuter" id="uArea">

                                <input type="text" id="loginuser" name="username" class="inputstyle"/>
                            </div>
                        </div>
                        <div class="pwdArea" id="pwdArea">
                            <label class="input-tips" for="p">密码：</label>
                            <div class="inputOuter" id="pArea">

                                <input type="password" id="loginpwd" name="p" class="inputstyle"/>
                            </div>
                        </div>

                        <div class="loginmsg" style='color:red;'></div>

                        <div style="padding-left:50px;margin-top:20px;">
                            <!-- <input type="submit" value="登 录" style="width:150px;" class="button_blue"/> -->
                            <input type="button" id="loginbtn" onclick="toLogin()" value="登 录" style="width:150px;" class="button_blue"/>

                        </div>
                    </div>
                    <!--  </form> -->
                </div>

            </div>

        </div>
        <!--登录end-->
    </div>


</div>
<div class="jianyi">*推荐使用ie8或以上版本ie浏览器或Chrome内核浏览器访问本站</div>

<script>
    var basepath = '<%=basePath%>';
    $(function () {
        $("#loginbtn").click(function () {
            var username = $.trim($("#loginuser").val());
            var password = $.trim($("#loginpwd").val());
            if (username == "") {
                $(".loginmsg").html("请输入用户名!");
                return;
            }
            if (password == "") {
                $(".loginmsg").html("请输入密码!");
                return;
            }
            var params = {
                username: username,
                password: password
            };

            $.ajax({
                type: "post",
                url: basepath + 'v1/login',
                datatype: "json",
                contentType: "application/json;charset=utf-8;",
                data: JSON.stringify(params),
                beforeSend: function () {
                    $(".loginmsg").html("登录中....");
                },
                complete: function () {

                },
                success: function (data) {
                    var statusCode = data.result;
                    var msg = data.msg;
                    console.log("statusCode====" + statusCode);
                    console.log("msg====" + msg);
                    if (statusCode != "1") {
                        $(".loginmsg").html(msg);
                    } else {
                        window.location.href = basepath + "forward/index";
                        $(".loginmsg").html("登录完成,页面跳转中...");

                    }
                },
                error: function () {
                    $(".loginmsg").html("登录失败,请联系管理员!");
                }
            });
        });
    });

    document.onkeydown = function (e) {
        if (e.keyCode == 13) {
            if ($(document.activeElement).attr("id") != "#loginbtn") {
                $("#loginbtn").click();
            }
        }
    }
</script>

</body>
</html>